﻿/**********************************************************************
*创建人：蔡水明
*创建时间：2020/10/29 21:08:26
*说明：<Function>
/**********************************************************************/
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
    /// <summary>
    /// 服务器返回数据格式
    /// </summary>
    public class RespData
    {
        public int code { get; set; }
        public int total { get; set; }
        public string msg { get; set; }
        public object data { get; set; }
        /// <summary>
        /// 生成返回数据
        /// </summary>
        /// <param name="data">要返回的数据</param>
        /// <param name="total">数据的数量</param>  
        /// <param name="code">状态码</param>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        public static RespData GetRes(int code = 0, int total = 1, string msg = "操作成功", object data = null)
        {
            RespData res = new RespData();
            res.code = code;
            res.msg = msg;
            res.data = data;
            res.total = total;
            return res;
        }
        /// <summary>
        /// 生成返回数据
        /// </summary>
        /// <param name="data">要返回的数据</param>
        /// <param name="total">数据的数量</param>  
        /// <param name="code">状态码</param>
        /// <param name="msg">消息</param>
        /// <returns></returns>
        public static RespData GetError(int code = -1, int total = 0, string msg = "出现错误", object data = null)
        {
            RespData res = new RespData();
            res.code = code;
            res.msg = msg;
            res.data = data;
            res.total = total;
            return res;
        }

        /// <summary>
        /// 返回空值错误
        /// </summary>
        /// <returns></returns>
        public static RespData GetNullResponse()
        {
            return GetRes(data: null, total: 0, code: -500, msg: "传入的数据为空,参数名称是否有误");
        }
        /// <summary>
        /// 返回Token错误
        /// </summary>
        /// <returns></returns>
        public static RespData GetTokenFail()
        {
            return GetRes(data: null, total: 0, code: -200, msg: "Token过期");
        }
        /// <summary>
        /// 返回数据库操作错误
        /// </summary>
        /// <returns></returns>
        public static RespData GetDatabaseError()
        {
            return GetRes(data: null, total: 0, code: -300, msg: "数据库操作失败");
        }
    }  
}
